# -*- coding:utf-8 -*-
import json

# @Time    : 2023/5/16 02:21
# @Author  : zengwenjia
# @Email   : zengwenjia@lingxi.ai
# @File    : generate_bot_dialogue.py
# @Software: LLM_internal
# 处理整通对话

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import pandas as pd
import asyncio
from bot.insurance_sales_huize.sales import Sales
# from bot.insurance_sales_huize.user import User
import uuid
from data_generate import utils
import traceback
import random
from loguru import logger


def conversation2csv(file_path):
    datas = utils.jload(file_path)
    df = pd.DataFrame(columns=['角色', '内容'])

    for data in datas:
        messages = data['messages']
        for text in messages:
            df = df._append(
                {"角色": text['role'],
                 "内容": text['content']},
                ignore_index=True)
        df = df.reset_index(drop=True)._append(
            {"角色": "",
             "内容": ""},
            ignore_index=True)
    df.to_csv(file_path.replace('.json', '.csv'))


if __name__ == '__main__':
    import datetime
    # df = pd.read_excel("转人500通-format.xlsx")
    df=pd.read_csv("小助手1211格式化.csv",header=None)
    for context in df[0]:
        sales = Sales()
        sales.conversation_history_str = context#sales.format_conversation_history(context)

        result = asyncio.run(
            sales.async_reply_web(context, '321', content=context,is_need_format=0))

        print(context,result)






